#include "common.h"

#define BORDER ' '

int resized = 0, quit = 0, max_x, max_y;
PANEL *main_panel = NULL;
CopticWindow *current_window = NULL;

void
make_topwin(CopticWindow * a)
{
	if (main_panel == NULL)
		main_panel = new_panel(a->ncwin);
	else
		replace_panel(main_panel, a->ncwin);

	current_window = a;
	wrefresh(a->ncwin);
	update_panels();
	doupdate();
}

void
refresh_if_topwin(CopticWindow * a)
{
	if (current_window == a)
		wrefresh(a->ncwin);
}

void
init_interface()
{
	stdscr = initscr();
	noecho();
	keypad(stdscr, TRUE);

	refresh();

	getmaxyx(stdscr, max_y, max_x);
}

void
destroy_interface()
{
	destroy_contact_list();

	erase();
	refresh();
	endwin();
}

void
draw_interface()
{
	/*
	 * Draw all borders 
	 */
	attron(A_REVERSE);
	mvvline(0, 0, BORDER, max_y);
	mvvline(0, max_x - 1, BORDER, max_y);
	mvvline(0, max_x - get_contact_list_width(), BORDER, max_y);
	mvhline(0, 0, BORDER, max_x);
	mvhline(max_y - 1, 0, BORDER, max_x);
	attroff(A_REVERSE);
	mvhline(max_y - 3, 1, 0, max_x - 1 - get_contact_list_width());
	refresh();

	/*
	 * Draw contact list 
	 */
	draw_contact_list();
}

gint
get_max_x()
{
	return max_x;
}

gint
get_max_y()
{
	return max_y;
}

void
redraw_interface()
{
	destroy_interface();
	init_interface();
	draw_interface();
}
